using GTA;
using GTA.Math;
using GTA.Native;

namespace CustomPeds;

public static class AnimationHelper
{
	public static void TaskPlayAnim(this Ped ped, string animDict, string animFile, int duration, bool Line = false, int flag = 0)
	{
		Function.Call(Hash._0xD3BD40951412FEF6, animDict);
		while (!Function.Call<bool>(Hash._0xD031A9162D01088C, animDict))
		{
			Script.Wait(25);
		}
		Function.Call(Hash._0xEA47FE3719165B94, ped, animDict, animFile, 8f, -4f, duration, flag, 0f, 0, 0, 0);
		if (!Line) return;
		Script.Yield();
		while (Function.Call<bool>(Hash._0x1F0B79228E461EC9, ped, animDict, animFile, 3))
		{
			Script.Wait(25);
		}
	}

	public static void TaskPlayAnim(this Ped ped, string animDict, string animFile, int duration, ref bool ImmediatelyStop, bool Line = false, string IncludeStopAnimFile = "", int flag = 0)
	{
		Function.Call(Hash._0xD3BD40951412FEF6, animDict);
		while (!Function.Call<bool>(Hash._0xD031A9162D01088C, animDict))
		{
			Script.Wait(25);
		}
		Function.Call(Hash._0xEA47FE3719165B94, ped, animDict, animFile, 8f, -4f, duration, flag, 0f, 0, 0, 0);
		if (Line)
		{
			Script.Yield();
			while (Function.Call<bool>(Hash._0x1F0B79228E461EC9, ped, animDict, animFile, 3) && !ImmediatelyStop)
			{
				Script.Wait(25);
			}
		}

		if (!ImmediatelyStop) return;
		Function.Call(Hash._0x28004F88151E03E0, ped, animFile, animDict, true);
		if (IncludeStopAnimFile != string.Empty)
		{
			Function.Call(Hash._0x28004F88151E03E0, Main.P1.Character, IncludeStopAnimFile, animDict, true);
		}
	}

	public static void TaskPlayAnimAdvanced(this Ped ped, string animDict, string animFile, int duration, int flag, float animTime, Vector3 position, Vector3 rotation)
	{
		Function.Call(Hash._0xD3BD40951412FEF6, animDict);
		while (!Function.Call<bool>(Hash._0xD031A9162D01088C, animDict))
		{
			Script.Wait(25);
		}
		Function.Call(Hash._0x83CDB10EA29B370B, ped, animDict, animFile, position.X, position.Y, position.Z, rotation.X, rotation.Y, rotation.Z, 8f, -4f, duration, flag, animTime, 2, 0);
	}

	public static void TaskPlayAnimLoop(this Ped ped, string animDict, string animFile, int duration)
	{
		Function.Call(Hash._0xD3BD40951412FEF6, animDict);
		while (!Function.Call<bool>(Hash._0xD031A9162D01088C, animDict))
		{
			Script.Wait(25);
		}
		Function.Call(Hash._0xEA47FE3719165B94, ped, animDict, animFile, 8f, -4f, duration, 1, 0f, 0, 0, 0);
	}

	public static bool IsEntityPlayingAnim(this Ped ped, string animDict, string animFile)
	{
		return Function.Call<bool>(Hash._0x1F0B79228E461EC9, ped, animDict, animFile, 3);
	}

	public static void SetEntityAnimCurrentSpeed(this Ped ped, string animDict, string animFile, float speed)
	{
		Function.Call(Hash._0x28D1A16553C51776, ped, animDict, animFile, speed);
	}

	public static double GetEntityAnimCurrentTime(this Ped ped, string animDict, string animFile)
	{
		return Function.Call<double>(Hash._0x346D81500D088F42, ped, animDict, animFile);
	}

	public static void SetEntityAnimCurrentTime(this Entity entity, string animDict, string animFile, float time)
	{
		Function.Call(Hash._0x4487C259F0F70977, entity, animDict, animFile, time);
	}
}
